package com.bookmanagement.mapper;

import com.bookmanagement.DTO.BookSearchDTO;
import com.bookmanagement.entity.Book;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author skyjay
 */
@Mapper
public interface BookMapper {


    List<Book> getBatchByID(List<Long> parse);

    @Update("update book set is_collected = 0 where id = #{bookId}")
    void cancelCollection(Integer bookId);

    @Update("update book set is_collected = 1 where id = #{bookId}")
    void addCollection(Integer bookId);

    @Select("select * from book where id = #{bookId}")
    Book getById(Long bookId);

    List<Book> getRecommendBooks();

    @Update("update book set stock = stock - 1 where id = #{bookId}")
    void reduceStock(Long bookId);

    @Update("update book set stock = stock + 1 where id = #{id}")
    void addStock(Integer id);

    @Select("select * from book where id = #{id} and status=1")
    Book getByIdWithStatus(Long aLong);

    List<Book> searchBook(BookSearchDTO bookSearchDTO);

    // 管理端：插入图书
    void insertBook(Book book);

    // 管理端：更新图书信息
    void updateBook(Book book);

    // 管理端：逻辑删除（修改status为0）
    @Update("update book set status = 0 where id = #{id}")
    void deleteBook(Long id);

    // 管理端：获取所有图书（包括下架的）
    @Select("select * from book order by create_at desc")
    List<Book> getAllBooks();
}
